package com.ruoyi.tester.controller;

import java.util.List;

import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.tester.domain.TesterLoginConfig;
import com.ruoyi.tester.service.ITesterLoginConfigService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 登录配置Controller
 * 
 * @author SJ
 * @date 2022-04-24
 */
@Controller
@RequestMapping("/tester/login_config")
public class TesterLoginConfigController extends BaseController
{
    private String prefix = "tester/login_config";

    @Autowired
    private ITesterLoginConfigService testerLoginConfigService;

    @RequiresPermissions("tester:login_config:view")
    @GetMapping()
    public String login_config()
    {
        return prefix + "/login_config";
    }

    /**
     * 查询登录配置列表
     */
    @ApiOperation("查询登录配置列表")
    @RequiresPermissions("tester:login_config:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TesterLoginConfig testerLoginConfig)
    {
        startPage();
        List<TesterLoginConfig> list = testerLoginConfigService.selectTesterLoginConfigList(testerLoginConfig);
        return getDataTable(list);
    }

    /**
     * 导出登录配置列表
     */
    @RequiresPermissions("tester:login_config:export")
    @Log(title = "登录配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TesterLoginConfig testerLoginConfig)
    {
        List<TesterLoginConfig> list = testerLoginConfigService.selectTesterLoginConfigList(testerLoginConfig);
        ExcelUtil<TesterLoginConfig> util = new ExcelUtil<TesterLoginConfig>(TesterLoginConfig.class);
        return util.exportExcel(list, "登录配置数据");
    }

    /**
     * 新增登录配置
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存登录配置
     */
    @ApiOperation("新增保存登录配置")
    @RequiresPermissions("tester:login_config:add")
    @Log(title = "登录配置", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TesterLoginConfig testerLoginConfig)
    {
        testerLoginConfigService.insertTesterLoginConfig(testerLoginConfig);
        return success(testerLoginConfig.getLoginConfigId());
    }

    /**
     * 修改登录配置
     */
    @RequiresPermissions("tester:login_config:edit")
    @GetMapping("/edit/{loginConfigId}")
    public String edit(@PathVariable("loginConfigId") Long loginConfigId, ModelMap mmap)
    {
        TesterLoginConfig testerLoginConfig = testerLoginConfigService.selectTesterLoginConfigByLoginConfigId(loginConfigId);
        mmap.put("testerLoginConfig", testerLoginConfig);
        return prefix + "/edit";
    }

    /**
     * 修改保存登录配置
     */
    @ApiOperation("修改保存登录配置")
    @RequiresPermissions("tester:login_config:edit")
    @Log(title = "登录配置", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TesterLoginConfig testerLoginConfig)
    {
        return toAjax(testerLoginConfigService.updateTesterLoginConfig(testerLoginConfig));
    }

    /**
     * 删除登录配置
     */
    @ApiOperation("删除登录配置")
    @RequiresPermissions("tester:login_config:remove")
    @Log(title = "登录配置", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(testerLoginConfigService.deleteTesterLoginConfigByLoginConfigIds(ids));
    }
}
